/**
 *
 * Created by Song,Yewen, 9/9/2011 2:56:38 PM
 *
 */


function  validateVideoUrl(ori_url) 
{
	const URL_GET_XML = "%1/player_config.xml";
	var html = download_page(ori_url);
	var xml_url = strFormat(URL_GET_XML, ori_url)
	if(!xml_url){
		// Not Found
	  	return 'NotFoundVideo';
	}
	
	var xml_str = download_page(xml_url);
	var flv_string = parse_xml(xml_str, 'file');	
	
	//var matches = html.match(/<title>(.*?)<\/title>/);
	var matches = html.match(/<title>([\s\S]*?)<\/title>/);
    if(matches){
       //<strong>01:46</strong>
       var time_str = copyBetween(html, '<strong>','</strong>');
       var duration = 0;
       var hour;
       var minute;
       var second;
       if (time_str.length == 5) {
           minute = time_str.substring(0,2);
           second = time_str.substring(3,5);
           duration = parseInt(minute) * 60 + parseInt(second);
       } else if(time_str.length == 8) {
           hour   = time_str.substring(0,2);
           minute = time_str.substring(3,5);
           second = time_str.substring(6,8);
           duration = parseInt(hour) * 3600 + parseInt(minute) * 60 + parseInt(second);
       }
 	   return 'success_title:' + encodeURIComponent(matches[1])
 	          + '\n video_urls:' + encodeURIComponent(flv_string)
 	          + '\n seconds:' + Math.round(parseInt(duration));
 	          ;
    }
    return 'error:empty_path';
}

/* http://www.cinemavip.com/videos/espot-demo-feria-de-la-musica */
function js_get_media_url(ori_url) 
{
    const URL_GET_XML = "%1/player_config.xml";
	var html = download_page(ori_url);
	var xml_url = strFormat(URL_GET_XML, ori_url)
	var xml_str = download_page(xml_url);
	var flv_string = parse_xml(xml_str, 'file');

	return flv_string;
}
